/**
 * Copyright (c) 2024 Huawei Technologies Co., Ltd.
 * This file is a part of the CANN Open Software.
 * Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */

#include "lib/reduce/mean_tiling.h"
#include "register/tilingdata_base.h"
namespace AscendC {
constexpr uint32_t MEAN_CALC_PROC = 1;
const uint32_t MEAN_ONE_BLK_SIZE = 32;
const uint32_t MEAN_ONE_REPEAT_BYTE_SIZE = 256;
const uint32_t HALF_TYPE_SIZE = 2;
const uint32_t FLOAT_TYPE_SIZE = 4;
void GetMeanMaxMinTmpSize(const uint32_t n, const uint32_t srcTypeSize,
    const uint32_t accTypeSize, const bool isReuseSource, uint32_t& maxSize, uint32_t& minSize)
{
    (void)isReuseSource;
    if (srcTypeSize == 0) {
        return;
    }
    uint32_t elementNumPerRep = MEAN_ONE_REPEAT_BYTE_SIZE / srcTypeSize;
    uint32_t repeatTimes = (n + elementNumPerRep - 1) / elementNumPerRep;
    uint32_t finalWorkSize = (repeatTimes + MEAN_ONE_BLK_SIZE - 1) / MEAN_ONE_BLK_SIZE * MEAN_ONE_BLK_SIZE;
    uint32_t inner = (n * srcTypeSize + MEAN_ONE_BLK_SIZE - 1) / MEAN_ONE_BLK_SIZE * MEAN_ONE_BLK_SIZE / srcTypeSize;
    if (srcTypeSize == HALF_TYPE_SIZE && accTypeSize == FLOAT_TYPE_SIZE) {
        elementNumPerRep = MEAN_ONE_REPEAT_BYTE_SIZE / FLOAT_TYPE_SIZE;
        repeatTimes = (n + elementNumPerRep - 1) / elementNumPerRep;
        finalWorkSize = (repeatTimes + MEAN_ONE_BLK_SIZE - 1) / MEAN_ONE_BLK_SIZE * MEAN_ONE_BLK_SIZE +
                        inner * FLOAT_TYPE_SIZE;
    }
    maxSize = minSize = finalWorkSize;
}

void GetMeanTmpBufferFactorSize(const uint32_t typeSize, uint32_t &maxLiveNodeCount, uint32_t &extraBuffer)
{
    auto calcFactor = MEAN_CALC_PROC;
    extraBuffer = 0;
    maxLiveNodeCount = calcFactor;
}
}  // namespace AscendC
